﻿using System.ServiceModel;
using Framework.Core;
using Framework.Core.Io;
using Framework.Remoting.Client;
using Framework.Wcf.ServiceContract;
using log4net;

namespace Framework.Wcf.Consumer
{
    public class EntryPoint : IEntryPoint
    {
        private readonly IServiceClientFactory serviceClientFactory;
        private readonly IConsoleAdapter consoleAdapter;
        internal static ILog Logger = LogManager.GetLogger(typeof (EntryPoint));

        public EntryPoint(IServiceClientFactory serviceClientFactory, IConsoleAdapter consoleAdapter)
        {
            this.serviceClientFactory = serviceClientFactory;
            this.consoleAdapter = consoleAdapter;
        }

        public void Run(EnvMode envMode)
        {
            var wcfClient = serviceClientFactory.CreateProxy<IPouet>(envMode);

            var toto = wcfClient.HelloWorld();
            Logger.Debug(toto.Name);

            try
            {
                wcfClient.HelloWorldException();
            }
            catch (FaultException<MyFault> e)
            {
                Logger.Error(e.Detail.Info);
            }

            consoleAdapter.Read();
        }
    }
}